using System;
using System.Text;
//using System.Windows.Forms;
using System.Drawing;
using cs2335.lab5;

namespace Demo_application
{
    class Demo1 : CCTForm
    {
        System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
        Button startButton = new cs2335.lab5.Button();
        Button pauseButton = new cs2335.lab5.Button();
        Button resetButton = new cs2335.lab5.Button();
        Label countDownLabel = new cs2335.lab5.Label();
        Label bang = new cs2335.lab5.Label();
        ProgressBar progress = new cs2335.lab5.ProgressBar();
        DomainUpDown domain = new cs2335.lab5.DomainUpDown();
        ListBox listbox;
        Menu foldersMenu; // sdavis31 - menu object

        int count;

        public Demo1()
        {
            timer.Interval = 1000;
            timer.Tick += new EventHandler(timer_tick);

            startButton.Text = "start";
            startButton.Click += new EventHandler(startButton_Click);
            startButton.Location = new Point(20, 20);

            pauseButton.Text = "pause";
            pauseButton.Click += new EventHandler(pauseButton_Click);
            pauseButton.Location = new Point(20, 60);

            resetButton.Text = "reset";
            resetButton.Click += new EventHandler(resetButton_Click);
            resetButton.Location = new Point(20, 100);

            countDownLabel.Location = new Point(150, 60);

            bang.Font = new Font("SansSerif", 18);
            bang.Location = new Point(150, 20);
            bang.Text = "BANG";
            bang.Hide();

            /// create a new listbox at x = 20, y = 140
            listbox = new cs2335.lab5.ListBox(new Point(20, 140), new Size(200, 96), this);

            listbox.AddListBoxEntry("item 1");
            listbox.AddListBoxEntry("item 2");
            listbox.AddListBoxEntry("item 3");
            listbox.AddListBoxEntry("item 4");
            listbox.AddListBoxEntry("item 5");
            listbox.AddListBoxEntry("item 6");
            listbox.AddListBoxEntry("hidden 1");
            listbox.AddListBoxEntry("hidden 2");
            listbox.AddListBoxEntry("hidden 3");
            listbox.AddListBoxEntry("hidden 4");
            listbox.AddListBoxEntry("hidden 5");
            listbox.AddListBoxEntry("hidden 6");
            listbox.AddListBoxEntry("hidden 7");
            listbox.AddListBoxEntry("hidden 8");

            foldersMenu = new Menu("Menu");
            foldersMenu.Owner = this;
            foldersMenu.Location = new Point(400, 150);
            MenuItem m = new MenuItem("File");
            foldersMenu.AddMenuItem(m);
            m = new MenuItem("Save");
            foldersMenu.AddMenuItem(m);
            m = new MenuItem("Exit");
            foldersMenu.AddMenuItem(m);

            /*
            foreach (MenuItem mi in foldersMenu.MenuItemList)
            {
                mi.Click += new EventHandler(menuItem_Click);
            }
             */
            this.Add(foldersMenu);    

            /*
            foldersMenu = new cs2335.lab5.Menu("Message Menu", 400, 150);
            foldersMenu.AttachParentMenu(foldersMenu);
            foreach (MenuItem mi in foldersMenu.MenuItemList)
            {
                mi.Click += new EventHandler(foldersMenuItem_Click);
            }
            */

            count = 30;
            countDownLabel.Text = "00:" + count;

            domain.Location = new Point(150, 20);
            domain.Items.Add("Hello");
            domain.Items.Add("World");
            domain.Items.Add("!");
            this.Add(domain);
            
            progress.Step = 1;
            progress.Maximum = 30;
            progress.Value = 10;
            progress.Location = new Point(150, 100);
            this.Add(progress);

            Sprite sprite = new Sprite();
            sprite.Bounds = new Rectangle(290, 20, 50, 50);
            this.Add(sprite);

            TextBox txtBox = new TextBox();
            txtBox.Location = new Point(290, 80);
            this.Add(txtBox);

            ComboBox combo = new ComboBox();
            // Currently, height field is combined height of single line + dropdown
            combo.Bounds = new Rectangle(290, 120, 100, 100);
            combo.Items.Add("Hello");
            combo.Items.Add("World");
            combo.Items.Add("This");
            combo.Items.Add("is");
            combo.Items.Add("a");
            combo.Items.Add("lot");
            combo.Items.Add("of");
            combo.Items.Add("filler");
            combo.MultiSelect = true;
            this.Add(combo);

            RadioGroup group = new RadioGroup();
            group.Bounds = new Rectangle(400, 20, 100, 25);

            RadioButton radio = new cs2335.lab5.RadioButton();
            radio.Text = "Button 1";
            group.Add(radio);
            radio.Text = "Button 2";
            group.Add(radio);
            radio.Text = "Button 3";
            group.Add(radio);
            this.Add(group);
            
            ///////Use these to run with CCT////////
            this.Add(startButton);
            this.Add(pauseButton);
            this.Add(resetButton);
            this.Add(countDownLabel); 
            this.Add(bang);

            this.Add(listbox);

            this.Size = new Size(600, 300);

            // begin sdavis31 - adding menu to form
            this.Add(foldersMenu);
            foreach (MenuItem mi in foldersMenu.MenuItemList)
            {
                this.Add(mi);
            }
            // end sdavis31        
        
        }

        void resetButton_Click(object sender, EventArgs e)
        {
            bang.Hide();
            count = 30;
            countDownLabel.Text = "00:" + count;

            progress.Value = 0;

            this.Invalidate();
        }

        void pauseButton_Click(object sender, EventArgs e)
        {
            timer.Enabled = false;
        }

        void startButton_Click(object sender, EventArgs e)
        {
            timer.Enabled = true;
        }
        
        private void timer_tick(object sender, EventArgs e)
        {
            if (count > 0)
            {
                count--;
                countDownLabel.Text = "00:" + count;

                progress.PerformStep();

                this.Invalidate();
            }
            else
            {
                timer.Enabled = false;
            }

            if (count == 0)
            {
                bang.Show();
            }
        }
        
        public static void Main()
        {
            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
            System.Windows.Forms.Application.Run(new Demo1());
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();

            this.Width = 700;
            this.Height = 300;
            this.Bounds = new Rectangle(0, 0, this.Width, this.Height);
            this.ClientSize = new System.Drawing.Size(this.Width, this.Height);
            this.Size = new Size(this.Width, this.Height);
            this.Name = "Demo1";
            this.ResumeLayout(false);
        }

        /*
        /// <summary>
        /// sdavis31 - click event handler for menu
        /// </summary>
        /// <param name="sender">sender object</param>
        /// <param name="e">event arguments</param>
        void foldersMenuItem_Click(object sender, EventArgs e)
        {
            if (foldersMenu.Open && foldersMenu.CurrentMenuItem.Name == "Happy Message")
            {
                System.Windows.Forms.MessageBox.Show("You made an A!");
            }
            else if (foldersMenu.Open && foldersMenu.CurrentMenuItem.Name == "Sad Message")
            {
                System.Windows.Forms.MessageBox.Show("You made an F!");
            }
            else if (foldersMenu.Open && foldersMenu.CurrentMenuItem.Name == "Ambivalent Message")
            {
                System.Windows.Forms.MessageBox.Show("You made no grade!");
            }
        }
        */

        void menuItem_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.MessageBox.Show(((MenuItem)sender).Text + " Clicked");
        }
    }
}
